package com.example.practical_training_projects.controller;

import com.example.practical_training_projects.service.GetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api")
@CrossOrigin


public class GetsController {
    @Autowired
    private GetsService getsService;

    @PostMapping("/toggle-get")
    public ResponseEntity<?> toggleGet(@RequestBody Map<String, Object> payload) {
        Integer userUid = Integer.parseInt((String) payload.get("userUid"));
        Integer contentUid = Integer.parseInt((String) payload.get("contentUid"));
        String contentType = (String) payload.get("contentType");

        getsService.toggleGet(userUid, contentType, contentUid);
        int getsCount = getsService.getGetsCount(contentType, contentUid);

        return ResponseEntity.ok().body(Map.of("gets", getsCount));
    }
}